var AddThis_ContextMenu = {

	init : function() {
		AddThis_Util.dbg("ContextMenu.init: initting...");
		AddThis_Util.dbg("ContextMenu.init: done.");
	},
    
    prepare: function()
    {
        AddThis_Util.dbg("ContextMenu.prepare: go...");
        
        var url, title;
        var mediaURL = 'mediaURL' in gContextMenu ? gContextMenu.mediaURL : gContextMenu.imageURL; 
        if (gContextMenu.onLink === true && gContextMenu.onSaveableLink === true)
		{
            url = 'getLinkURL' in gContextMenu ? gContextMenu.getLinkURL() : gContextMenu.linkURL(); 
            if (gContextMenu.onImage === true && gContextMenu.imageURL !== "")
		    {
                title = this._getTitleFromImage(gContextMenu.target);
            }
            else title = gContextMenu.linkText();
            if (!title) title = "";
		}
		else if (gContextMenu.onImage === true && mediaURL !== "")
        {
    		var urlObj = AddThis_Util.convertURLToObject(gBrowser.contentDocument.location.href);
            url = AddThis_Util.resolveURL(urlObj.spec, mediaURL.toString());
            title = this._getTitleFromImage(gContextMenu.target);
            if (!title) title = "";
		}
        
        
        
        AddThis_Util.dbg("ContextMenu.prepare: url: " + url + " title: " + title);
        AddThis_Sharing.initShareMenu("at_contextMenuPopup", url, title);
    },
    
    _getTitleFromImage: function(target)
    {
        var title="";
		if (target.localName.toUpperCase() == "IMG")
		{
			title = target.getAttribute("title");
			if (!title)
			{
				title = target.getAttribute("alt");
                if (!title)
				{
					title = "";
				}
			}
		}
        return title;
     },
    
    
    setVisibility: function()
    {
        AddThis_Util.dbg("ContextMenu.setVisibility: go...");
        var cm = document.getElementById("at_contextMenu");
        cm.setAttribute("hidden", AddThis_Util.getBooleanPref("extensions.addthis.contextmenu.disable",false));
    },
    
    isVisible : function(doc) {
        if (typeof doc == "undefined") doc = document;
        var visible = !doc.getElementById("at_contextMenu").hidden;
        AddThis_Util.dbg("ContextMenu.isVisible: " + visible);
        return visible;
    }
};